#include "slist.h"
#include <stdio.h>
#include <stdlib.h>
/*
hello world
1
2
3
4
45
5
-1
1 2 3 4 45 5 
*/

/* 打印单个节点信息 */
int my_print(void *data);
/* 销毁单个节点 */  
int my_destroy(void *data);


int main(int argc, char **argv)
{
#ifdef DEBUG
    printf("hello world\n");
#endif

    /* 变量定义 */
    slist_t *s = NULL;
    int num = 0;

    /* 创建结构体 */
    slist_create(&s, sizeof(int), my_destroy);

    while (1)
    {
    op:
        my_scanf(op, "%d", &num);

        if (num == -1)
        {
            break;
        } /* end of if (num == -1) */

        slist_append(s, &num);


    } /* end of while (1) */

    slist_traverse(s, my_print);

    slist_destroy(s);

    return 0;
}

/* 打印单个节点信息 */
int my_print(void *data)
{
    /* 变量定义 */
    node_t *tmp = data;

    /* 参数检查 */
    if (NULL == data)
    {
        perror("argument lawless...");
        goto err0;
    } /* end of  if (NULL == data) */

    /* 打印函数 */
    printf("%d ", *(int *)(tmp->data));


    return 0;
err0:
    return -1;
}

/* 销毁单个节点 */  
int my_destroy(void *data)
{
    /* 变量定义 */
    node_t *tmp = data;

    /* 参数检查 */
    if (NULL == data)
    {
        perror("argument failed...");
        goto err0;
    } /* end of if (NULL == data) */

    /* 销毁变量 */
    free(tmp->data);
    tmp->data = NULL;
    free(tmp);
    tmp = NULL;

    return 0;
err0:
    return -1;
}